﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BEELab
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        /// <summary>
        /// Occures on every page load (first time or Post Back)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// Function that used to reset user's password
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Session["UserEmail"] != null)
            {
                bool res = BEELab.Logic.UserManagement.ChangePassword(Session["UserEmail"].ToString(), txtCurrentPassword.Text, txtNewPassword.Text);

                //If res is false, update didn't succeed. Message will be presented "* Password is wrong"
                if (!res)
                {
                    lblVerifyPassword.Visible = true;
                }
                else
                {
                    lblVerifyPassword.Visible = false;
                }

                //Clear all fields on screen
                txtNewPassword.Text = "";
                txtCurrentPassword.Text = "";
                txtConfirmeNewPassword.Text = "";
            }
        }
    }
}